package com.wh.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wh.mapper.FirstDepartMapper;
import com.wh.mapper.SecondDepartMapper;
import com.wh.model.dto.FirstDepartMentDto;
import com.wh.model.pojo.FirstDepartMent;
import com.wh.model.pojo.SecondDepartMent;
import com.wh.service.FirstDepartService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: wh(1835734390 @ qq.com)
 * @date: 2022/11/18 22:34
 * @description:
 * @version:
 */
@Service
public class FirstDepartServiceImpl extends ServiceImpl<FirstDepartMapper, FirstDepartMent> implements FirstDepartService {
    @Autowired
    FirstDepartMapper firstDepartMapper;
    @Autowired
    SecondDepartMapper secondDepartMapper;
    @Override
    public List<FirstDepartMentDto> getAllDep() {
        List<FirstDepartMentDto> list = new ArrayList<>();
        List<FirstDepartMent> firstDepartMents = firstDepartMapper.selectList(null);
        for (int i = 0; i < firstDepartMents.size(); i++) {
            FirstDepartMent firstDepartMent = firstDepartMents.get(i);
            List<SecondDepartMent> secondDepartList = secondDepartMapper.getSecondDepartList(firstDepartMent.getId());
            FirstDepartMentDto firstDepartMentDto = new FirstDepartMentDto();
            BeanUtils.copyProperties(firstDepartMent,firstDepartMentDto);
            firstDepartMentDto.setChild(secondDepartList);
            list.add(firstDepartMentDto);
        }
        return list;
    }
}
